home *** CD-ROM | disk | FTP | other *** search
Text File | 1995-02-07 | 2.6 KB | 114 lines | [TEXT/MPS ] |
- (*
- CTBSendWithLF string[,eom] -- Send a string out the current connection, adding linefeeds after every
- carriage return in the string. If the eom parameter is present and non-empty, then set the
- end-of-message bit when sending.
-
- To compile and link this file using Macintosh Programmer's Workshop,
-
- pascal -w CTBSendWithLF.p
- link -m ENTRYPOINT -o HyperCommands -rt XCMD=2765 -sn Main=CTBSendWithLF ∂
- CTBSendWithLF.p.o "{MPW}"Libraries:interface.o "{MPW}"Libraries:Libraries:HyperXLib.o
-
- © Copyright 1990 by Apple Computer, Inc.
-
- Initial coding 2/90 by Harry R. Chesley.
- *)
-
- {$R-}
-
- {$S CTBSendWithLF } { Segment name must be the same as the command name. }
-
- unit DummyUnit;
-
- interface
-
- uses MemTypes, QuickDraw, OSIntf, ToolIntf, CTBUtils, FTIntf, CMIntf, TMIntf, CRMIntf, HyperXCmd;
-
- procedure EntryPoint(paramPtr: XCmdPtr);
-
- implementation
-
- procedure CTBSendWithLF(paramPtr: XCmdPtr); forward;
-
- procedure EntryPoint(paramPtr: XCmdPtr);
-
- begin
- CTBSendWithLF(paramPtr);
- end;
-
- procedure CTBSendWithLF(paramPtr: XCmdPtr);
-
- {$I CTBUtil.inc}
-
- const linefeed = 10; { ASCII for line feed. }
- return = 13; { ASCII for carriage return. }
-
- var i: integer;
- flags: CMFlags;
- p, p2: Ptr;
- newP: Ptr;
- l: longInt;
- h: Handle;
- err: CMErr;
-
- procedure Fail(errMsg: Str255); { set theResult and quit }
- begin
- paramPtr^.returnValue := PasToZero(paramPtr,errMsg);
- exit(CTBSendWithLF);
- end;
-
- begin
- { Check the parameter count. }
- i := paramPtr^.paramCount;
- if (i = 0) or (i > 2) then Fail('Invalid parameter count');
-
- { Check for an empty string being sent. }
- if not ParmPresent(1) then exit(CTBSendWithLF);
- h := paramPtr^.params[1];
-
- { Make sure the Comm Toolbox is here. }
- CTBReady;
- { And a connection tool is available. }
- EnsurePresent(connectionTool);
- { And it's open. }
- EnsureOpen;
-
- { Figure out if we should set the EOM flag. }
- if ParmPresent(2) then flags := cmFlagsEOM
- else flags := 0;
-
- { Count the bytes, adding in space for the linefeeds. }
- l := 0;
- p := h^;
- while p^ <> 0 do
- begin
- if p^ = return then l := l+1;
- p := Ptr(ord4(p)+1);
- l := l+1;
- end;
-
- { Allocate a new pointer for the modified input. }
- newP := NewPtr(l);
- if newP = nil then Fail('Could not allocate memory for write');
- { Copy it in, adding linefeeds. }
- p := h^;
- p2 := newP;
- while p^ <> 0 do
- begin
- p2^ := p^;
- p2 := Ptr(ord4(p2)+1);
- if p^ = return then
- begin
- p2^ := linefeed;
- p2 := Ptr(ord4(p2)+1);
- end;
- p := Ptr(ord4(p)+1);
- end;
- { Write it out. }
- err := CMWrite(Globals^^.connHand,newP,l,cmData,false,nil,-1,flags);
- DisposPtr(newP);
- if err <> noErr then Fail('Write failed');
- end;
-
- end.
-